home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / entrdata.zip / ENTRDATA.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  6KB  |  207 lines

  1. { entrdata.pas - Data entry routines
  2.  
  3.   Based on Jim Lemay's PULL full featured pull-down menus. (v 5.Xb, 03-04-89)
  4.   Copyright (c) 1987-1989 James H. LeMay, All rights reserved.
  5.  
  6.   Modified for stand alone use by Gordon A. Feingold, System Dynamics.
  7.  
  8.   Version 1.0   06/03/89
  9. }
  10.  
  11. { TP5 directives }
  12. {$ifdef Debug}
  13. {$A-,B-,E-,F-,I-,N-,O-,V-}
  14. {$else}
  15. {$A-,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}
  16. {$endif}
  17.  
  18. UNIT EntrData;
  19.  
  20. INTERFACE
  21.  
  22. uses
  23.   Crt,Qwik,Wutil,Wndw,Strs;
  24.  
  25. type
  26.   WriteModeType = (ScrnRel, WndwRel); {[GAF]}
  27. const
  28.   {Set to ScrnRel for screen relative row & col use, WndwRel for wndw relative}
  29.   DataWriteMode : WriteModeType = ScrnRel;
  30.  
  31. { Former Inc: Data Vars...}
  32. const
  33.   MaxDataEntries   = 255;    {For new record format}
  34.   DataStrSize      = 100;    { Max chars in data entry string }
  35.  
  36. var
  37.   Key:             char;
  38.   ExtKey:          boolean;
  39.   AddrKbdIdle:     pointer;
  40.  
  41. const
  42.   WaitForKbd:      boolean = true;
  43.  
  44.   { -- Function keys -- }
  45.   F10Key  = #68;
  46.  
  47.   { -- Data Entry keys -- }
  48.   NullKey  = #00;
  49.   RetKey   = #13;   { ^M }
  50.   BSKey    = #08;
  51.   EscKey   = #27;   { ^[ }
  52.   HomeKey  = #71;
  53.   UpArrKey = #72;
  54.   PgUpKey  = #73;
  55.   LArrKey  = #75;
  56.   RArrKey  = #77;
  57.   EndKey   = #79;
  58.   DnArrKey = #80;
  59.   PgDnKey  = #81;
  60.   InsKey   = #82;
  61.   DelKey   = #83;
  62.   CtrlLArrKey = #115;
  63.   CtrlRArrKey = #116;
  64.   CtrlEndKey  = #117;
  65.   CtrlPgDnKey = #118;
  66.   CtrlHomeKey = #119;
  67.   CtrlPgUpKey = #132;
  68.   TabKey      = #9;
  69.   ShiftTabKey = #15;
  70.  
  71. type
  72.   ProcPtrType  = Pointer;
  73.   Toggle         = (Off, On, No, Yes);
  74.   TypeOfDataType = (
  75.     Bytes,Words,ShortInts,Integers,LongInts,Reals,UserNums,Chars,Strings);
  76.   SetNames = (
  77.     NoSet,UnsignedSet,SignedSet,RealSet,CharSet,HexSet,FileNameSet,PathSet,
  78.     MaskSet);
  79.   EntrySetArray  = array[UnsignedSet..MaskSet] of set of char;
  80.   DataEntryRec =
  81.     record
  82.       VarAddr:                  pointer;
  83.       TypeOfData:               TypeOfDataType;
  84.       Row,Col,Field,MaxField:   byte;
  85.       Decimals:                 shortint;
  86.       SetName:                  SetNames;
  87.       TranslateProc,
  88.       CheckRangeProc:           ProcPtrType;
  89.       JustifyOutput:            DirType;
  90.       Oattr, Iattr,
  91.       MsgLineNum, HelpWndwNum:  byte;
  92.     end;
  93.  
  94.   DataEntries = array[1..MaxDataEntries] of DataEntryRec;
  95.   DataEntriesPtr = ^DataEntries; {New type [GAF]}
  96.   DEGroupRec = record            {Record for each group's data entries}
  97.                  GroupPtr : DataEntriesPtr;
  98.                  NumInGroup : word;
  99.                end;
  100.   DataStrType = string[DataStrSize];
  101.   DataPadRec =
  102.     record
  103.       StoreMode,Valid,DataStored,NewData: boolean;
  104.       FieldIndex,CursorOfs,Hattr: integer;
  105.       ErrHandlerProc:   ProcPtrType; {Added [GAF]}
  106.       RangeOK: boolean; {Added [GAF]}
  107.       Flex:    byte;
  108.       Justify: DirType;
  109.       case TypeOfDataType of
  110.         Bytes:        (Bdata:  byte);
  111.         Words:        (Wdata:  word);
  112.         ShortInts:    (SIdata: shortint);
  113.         Integers:     (Idata:  integer);
  114.         LongInts:     (Ldata:  longint);
  115.         Reals:        (Rdata:  real);
  116.         UserNums:     (UNdata: DataStrType);
  117.         Chars:        (Cdata:  char);
  118.         Strings:      (Sdata:  DataStrType);
  119.     end;
  120.  
  121. const
  122.   { -- Filter sets for valid data entry characters -- }
  123.   EntrySet:  EntrySetArray = (
  124.    { -- Reserved sets -- }
  125.    { UnsignedSet: } ['0'..'9'],
  126.    { SignedSet:   } ['0'..'9','-','+'],
  127.    { RealSet:     } ['0'..'9','-','+','.','E','e'],
  128.    { CharSet:     } [' '..'~'],
  129.    { -- User customized sets -- }
  130.    { HexSet:      } ['0'..'9','A'..'F','a'..'f'],
  131.    { FileNameSet: }
  132.      ['!','#'..')','-'..'.','0'..'9','@'..'Z','^'..'{','}'..'~'],
  133.    { PathSet:     }
  134.      ['!','#'..')','-'..'.','0'..':','@'..'Z','^'..'{','}'..'~','\'],
  135.    { MaskSet:     }
  136.      ['!','#'..'*','-'..'.','0'..':','?'..'Z','^'..'{','}'..'~','\']);
  137.  
  138.   SeqDoneKey : char = NullKey; {To be set by user in SetDataEntryDefaults}
  139. var
  140.   DEI:             word;        { Top data entry record index }
  141.   TopEntry:        DataEntryRec;
  142.   DataEntry:       DataEntriesPtr; {Now of type DatEntriesPtr}
  143.   DataStr:         DataStrType;
  144.   DataStrL:        byte absolute DataStr;  { length of DataStr }
  145.   DataPad:         DataPadRec;
  146.   AutoTab,
  147.   AutoNumLock:     boolean;
  148.  
  149. { End Former Inc: Data Vars}
  150.  
  151.   DataEntryOattr,          { Default Output attribute }
  152.   DataEntryIattr : byte;   { Default Input  attribute }
  153.  
  154.  
  155. procedure ReadKbd (VAR ExtKey: boolean; VAR Key: char);
  156.  
  157. function StrSL  (S: string; Field: byte): string;
  158. function StrSR  (S: string; Field: byte): string;
  159. function InRangeW (Low,Value,High: word): boolean;
  160.  
  161. procedure Enter             (DEGroup : DEGroupRec; RecNum: word);
  162. procedure EnterSeq          (DEGroup : DEGroupRec; First,Last: word; VAR Start: word);
  163. procedure DisplayFields     (DEGroup : DEGroupRec; First,Last: word);
  164. procedure GetDataEntry      (DEGroup : DEGroupRec; Index: word);
  165. procedure SaveDataEntry;
  166. procedure AllocateDataEntries (var DEGroup : DEGroupRec; NumEntries : word);
  167. procedure RemoveDataEntries   (var DEGroup : DEGroupRec);
  168.  
  169. IMPLEMENTATION
  170.  
  171. {$L strs.obj }
  172. function StrSL; external;
  173. function StrSR; external;
  174.  
  175. {$L inrangew.obj }
  176. function InRangeW; external;
  177.  
  178. procedure CallKbdIdle;  { forward; }
  179. inline ($FF/$1E/AddrKbdIdle); { call DWORD PTR [>AddrKbdIdle] }
  180.  
  181. procedure MonitorKbd;
  182. begin
  183.   repeat
  184.     CallKbdIdle;
  185.   until keypressed;
  186. end;
  187.  
  188. procedure ReadKbd; { (VAR ExtKey: boolean; VAR Key: char); }
  189. begin
  190.   MonitorKbd;
  191.   Key := ReadKey;                        { Read keyboard input.       }
  192.   if KeyPressed and (Key=NullKey) then   { If first Char was Null ... }
  193.     begin
  194.       Key := ReadKey;                    { ... read second char.      }
  195.       ExtKey := true
  196.     end
  197.   else ExtKey := false;
  198. end;
  199.  
  200.  
  201. {$I EntrData.inc }    { the data entry routines }
  202.  
  203. BEGIN {EntrData Initialization}
  204.   {Set to nill in case it's not set in SetDataEntryDefaults}
  205.   DataPad.ErrHandlerProc:=nil;
  206. END.
  207.